package com.epalmpay.controller.shop;

import com.epalmpay.commom.BaseController;
import com.epalmpay.dto.bonus.BonusRuleIndexOutDTO;
import com.epalmpay.dto.bonus.BonusVerifyLogListOutDTO;
import com.epalmpay.dto.bonus.ShopBonusVerifyRule;
import com.epalmpay.dto.memberGrade.MemberGradeListOutDTO;
import com.epalmpay.dto.system.BaseOutDTO;
import com.epalmpay.exception.ApplicationException;
import com.epalmpay.service.bonus.IBonusRuleService;
import com.epalmpay.status.Rescode;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

/**
 * Created by Administrator on 2018/4/25.
 */
@Controller
@RequestMapping(value="/shop/bonus")
public class ShopBonusRuleController {

    @Resource
    private IBonusRuleService bonusRuleService;


    @RequestMapping("/index")
    @ResponseBody
    public BonusRuleIndexOutDTO index(ShopBonusVerifyRule bonusVerifyRule) {
        return bonusRuleService.shopBonusindex(bonusVerifyRule);
    }

    @RequestMapping("/goAddVerifyRule")
    @ResponseBody
    public BonusRuleIndexOutDTO goAddVerifyRule( ShopBonusVerifyRule bonusVerifyRule) {
        BonusRuleIndexOutDTO bonusRuleIndexOutDTO = new BonusRuleIndexOutDTO();
        try {
            bonusRuleIndexOutDTO= bonusRuleService.goAddVerifyRule(bonusVerifyRule);
            bonusRuleIndexOutDTO.setErrorCode(Rescode.SUCCESS, "处理成功");

            return bonusRuleIndexOutDTO;
        }catch (ApplicationException ae) {
            bonusRuleIndexOutDTO.setErrorCode(ae.errCode, ae.errMsg);
            ae.printStackTrace();
        }
        catch (Exception e) {
            bonusRuleIndexOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, "处理出现异常");
            e.printStackTrace();
        }
        return bonusRuleIndexOutDTO;
    }

    @RequestMapping("/verifyBonusAdd")
    @ResponseBody
    public BonusVerifyLogListOutDTO verifyBonusAdd( ShopBonusVerifyRule bonusVerifyRule) {
        BonusVerifyLogListOutDTO bonusVerifyLogListOutDTO = new BonusVerifyLogListOutDTO();
        try {
            bonusRuleService.verifyBonusAdd(bonusVerifyRule);
            bonusVerifyLogListOutDTO.setErrorCode(Rescode.SUCCESS, "处理成功");

            return bonusVerifyLogListOutDTO;
        }catch (ApplicationException ae) {
            bonusVerifyLogListOutDTO.setErrorCode(ae.errCode, ae.errMsg);
            ae.printStackTrace();
        }
        catch (Exception e) {
            bonusVerifyLogListOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, "处理出现异常");
            e.printStackTrace();
        }
        return bonusVerifyLogListOutDTO;
    }
}
